/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.webserver.inMemory;

import mb.config.Constants;
import mb.config.ConstantsMsg;
import mb.mbmiddle.MbPartMiddle;
import mb.mbpart.memory.BaseMemory;
import mb.utils.Utils;

/**
 *
 * @author thanh.nguyenchi
 */
public class ServiceDataProcess extends BaseProcess{
    int status;
    String error;
    String lang;
    long cachetime;
    String services;    // array 

    public ServiceDataProcess(String lang,String cachetime){
        this.lang = lang;
        this.cachetime = Utils.getLong(cachetime);
        process();
    }
    
    @Override
    public void process(){
        // lay danh sach diem giao dich
        BaseMemory objMem = (BaseMemory)MbPartMiddle.objMemory.get(Constants.STR_MEM_SERVIES);
        if (objMem != null){
            // Kiem tra            
            if (cachetime == objMem.getCachetime()){
                // du lieu cu ko can lay lai
                status = ConstantsMsg.INT_SUCESSFUL_CODE;
                error = "";   
                services = "[]";
            }
            else{
                // lay lai
                status = ConstantsMsg.INT_SUCESSFUL_CODE;
                error = "";   
                cachetime = objMem.getCachetime();
                services = objMem.getData();
            }
        }
        else{
            status = ConstantsMsg.INT_NO_DATA_FOUND;
            error = ConstantsMsg.getErrMsg(status,lang);
        }
        return;
    }
    
    @Override
    public String toJson(){ 
        String sResult = "";
        sResult = sResult + "{\"" + nStatus + "\":" + status;
        sResult = sResult + ",\"" + nError + "\":\"" + error + "\"";
        sResult = sResult + ",\"" + nCache + "\":" + cachetime;
        sResult = sResult + ",\"" + nServices + "\":" + services;
        sResult = sResult + "}";
        return sResult;
    }        
    
}
